package com.butterfly.hotkey.common.disruptor.publish;

import cn.hutool.core.util.StrUtil;
import com.butterfly.hotkey.core.constant.Constants;
import com.butterfly.hotkey.core.constant.NumConst;
import com.butterfly.hotkey.common.disruptor.container.IEventProcessorContainer;
import com.butterfly.hotkey.common.disruptor.event.QueueEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 事件发布器
 *
 * @author butterfly
 * @version 1.0
 */
public class QueueEventPublisher {

    private static final Logger log = LoggerFactory.getLogger(Constants.WORKER);

    /**
     * 保存所有的处理容器
     */
    private static final Map<String, IEventProcessorContainer> CONTAINER_MAP = new ConcurrentHashMap<>(NumConst.SIXTY_FOUR);

    public void addContainer(String topic, IEventProcessorContainer container) {
        CONTAINER_MAP.put(topic, container);
    }
    /**
     * 发布事件
     *
     * @param topic      topic
     * @param queueEvent 事件
     */
    public void publishEvent(String topic, QueueEvent queueEvent) {
        IEventProcessorContainer container = CONTAINER_MAP.get(topic);
        container.receiveQueueEvent(queueEvent);
    }


}
